function [out]=wrapp_around(img,window_size,center)
%computes the wrapping window according to a given window_size and center
%
%center is the pixel in the upper left corner of the grid, given by the
%axial alined rectangles, lying inside the rectangle/parallelogram given by
%one curvelet
%
% Author: Sebastian Schmelcher         Version: 2012-06-19

out=zeros(window_size);
img_size=size(img);
ys=img_size(1);
xs=img_size(2);

yc=center(1);
xc=center(2);

if(yc<1 || yc>ys || xc<1 || xc>xs)
    error('wrapp_around: Center not inside image!');
end

yw=window_size(1);
xw=window_size(2);

% Adding the four axial-alined rectangles with regards to image boundaries
out(max(-yc+yw+2,1):yw,max(-xc+xw+2,1):xw)=img(max(yc-yw,1):yc-1,max(xc-xw,1):xc-1); %upper left
out(max(-yc+yw+2,1):yw,1:min(xw,xw+xs-xc-xw+1))=out(max(-yc+yw+2,1):yw,1:min(xw,xw+xs-xc-xw+1))+img(max(yc-yw,1):yc-1,xc:min(xc+xw-1,xs)); %upper right
out(1:min(yw,yw+ys-yc-yw+1),max(-xc+xw+2,1):xw)=out(1:min(yw,yw+ys-yc-yw+1),max(-xc+xw+2,1):xw)+img(yc:min(yc+yw-1,ys),max(xc-xw,1):xc-1); %lower left
out(1:min(yw,yw+ys-yc-yw+1),1:min(xw,xw+xs-xc-xw+1))=out(1:min(yw,yw+ys-yc-yw+1),1:min(xw,xw+xs-xc-xw+1))+img(yc:min(yc+yw-1,ys),xc:min(xc+xw-1,xs)); %lower right

end